﻿Imports SchemaMikeConnellMinistries

Partial Class store_UCSermonLinks
    Inherits System.Web.UI.UserControl

    Public Sub Display(sermon As CProduct)
        With sermon
            Dim m As CProduct = Nothing
            If .IsSet And .Children.Manuals.Count > 0 Then
                m = .Children.Manuals(0)
            ElseIf .HasParent AndAlso .BelongsTo.Children.Manuals.Count > 0 Then
                m = .BelongsTo.Children.Manuals(0)
            End If
            If Not IsNothing(m) Then
                lnkManual.Visible = True
                If m.Files.HasHtm Then
                    lnkManual.NavigateUrl = CConfig.DropboxUrl(m.Files.FirstHtm.FileName)
                ElseIf m.Files.HasPdfOrWord Then
                    lnkManual.NavigateUrl = CConfig.DropboxUrl(m.Files.FirstPdfOrWord.FileName)
                Else
                    lnkManual.Visible = False
                End If
            End If

            'Audio
            If Not .IsSet AndAlso .HasAudio Then
                lnkAudio.NavigateUrl = CConfig.DropboxUrl(.Files.FirstMp3.FileName)
            Else
                lnkAudio.Visible = False
            End If

            'Notes
            If Not .IsSet AndAlso .Files.HasHtm Then
                lnkNotes.NavigateUrl = CConfig.DropboxUrl(.Files.FirstHtm.FileName)
            ElseIf Not .IsSet AndAlso .Files.HasPdfOrWord Then
                lnkNotes.NavigateUrl = CConfig.DropboxUrl(.Files.FirstPdfOrWord.FileName)
            Else
                lnkNotes.Visible = False
            End If

            If .ProductTypeId_ = EProductType.Manual Then lnkNotes.Visible = False

            'Video
            If .HasVideos Then
                lnkVimeo.NavigateUrl = .VideoUrl
                If .HasVideosOnBoth Then
                    lnkYouTube.Visible = True
                    lnkYouTube.NavigateUrl = .VideoUrl_YouTube
                    lnkVimeo.Text = "Vimeo"
                End If
                If .IsSet Then
                    lnkYouTube.ToolTip = lnkYouTube.ToolTip.Replace("Video", "Playlist")
                    lnkVimeo.ToolTip = lnkVimeo.ToolTip.Replace("Video", "Channel")
                End If
            ElseIf .HasParent AndAlso (.BelongsTo.HasVimeoChannel OrElse .BelongsTo.HasYouTubePlaylist) Then
                lnkVimeo.NavigateUrl = .BelongsTo.VideoUrl_VimeoChannel
                If .BelongsTo.HasYouTubePlaylist Then
                    lnkYouTube.Visible = True
                    lnkYouTube.NavigateUrl = .VideoUrl_YouTubePlaylist
                    lnkVimeo.Text = "Vimeo"
                End If
                lnkYouTube.ToolTip = lnkYouTube.ToolTip.Replace("Video", "Playlist")
                lnkVimeo.ToolTip = lnkVimeo.ToolTip.Replace("Video", "Channel")
            Else
                lnkVimeo.Visible = False
            End If


            plhHasTranscript.Visible = .HasTranscript OrElse .Children.HavingTranscripts.Count > 0 OrElse .Files.HasEpub OrElse .Files.HasMobi OrElse (.HasParent AndAlso .BelongsTo.Files.HasEpub)
            If .HasTranscript Then
                lnkHtml.NavigateUrl = CSitemap.TranscriptWithPaging(sermon)
            ElseIf .Children.HavingTranscripts.Count > 0 Then
                lnkHtml.NavigateUrl = CSitemap.Transcript(sermon)
            ElseIf .HasParent AndAlso .BelongsTo.Children.HavingTranscripts.Count > 0 Then
                lnkHtml.NavigateUrl = CSitemap.TranscriptWithPaging(sermon.BelongsTo)
            Else
                lnkHtml.Visible = False
            End If

            If .HasTranscriptChineseSimp OrElse .HasTranscriptChineseTrad Then
                plhHasChinese.Visible = True
                lnkChineseSimp2.Visible = .HasTranscriptChineseSimp
                lnkChineseTrad2.Visible = .HasTranscriptChineseTrad
                lnkChineseSimp2.NavigateUrl = CSitemap.TranscriptChineseSimplified(sermon)
                lnkChineseTrad2.NavigateUrl = CSitemap.TranscriptChineseTraditional(sermon)
            End If


            If .Files.HasMobi Then ' AndAlso (.IsFree OrElse .IsDonateButton) Then
                lnkMobi.NavigateUrl = CConfig.DropboxUrl(.Files.FirstMobi.FileName)
            ElseIf .HasParent AndAlso .BelongsTo.Files.HasMobi Then 'AndAlso (.BelongsTo.IsFree OrElse .BelongsTo.IsDonateButton) Then
                lnkMobi.NavigateUrl = CConfig.DropboxUrl(.BelongsTo.Files.FirstMobi.FileName)
                ' ElseIf .HasTranscript Then
                '     lnkMobi.NavigateUrl = CSitemap.MOBI_URL
            Else
                lnkMobi.Visible = False
            End If


            If .Files.HasEpub Then 'AndAlso (.IsFree OrElse .IsDonateButton) Then
                lnkEPub.NavigateUrl = CConfig.DropboxUrl(.Files.FirstEpub.FileName)
            ElseIf .HasParent AndAlso .BelongsTo.Files.HasEpub Then 'AndAlso (.BelongsTo.IsFree OrElse .BelongsTo.IsDonateButton) Then
                lnkEPub.NavigateUrl = CConfig.DropboxUrl(.BelongsTo.Files.FirstEpub.FileName)
                'ElseIf .HasTranscript Then
                '    lnkEPub.NavigateUrl = CSitemap.EPUB_URL
            Else
                lnkEPub.Visible = False
            End If

            If String.IsNullOrEmpty(lnkHtml.NavigateUrl) Then
                If .Files.HasHtm Then
                    lnkHtml.Visible = True
                    lnkHtml.NavigateUrl = CConfig.DropboxUrl(.Files.FirstHtm.FileName)
                ElseIf .HasParent AndAlso .BelongsTo.Files.HasHtm Then
                    lnkHtml.Visible = True
                    lnkHtml.NavigateUrl = CConfig.DropboxUrl(.BelongsTo.Files.FirstHtm.FileName)
                End If
            End If

            If Not String.IsNullOrEmpty(.ProductAmazonId) Then
                lnkAmazon.NavigateUrl = CSitemap.External_Amazon(.ProductAmazonId, .ProductName)
            ElseIf .HasParent AndAlso Not String.IsNullOrEmpty(.BelongsTo.ProductAmazonId) Then
                lnkAmazon.NavigateUrl = CSitemap.External_Amazon(.BelongsTo.ProductAmazonId, .BelongsToName)
            Else
                'lnkAmazon.Visible = False
                lnkAmazon.NavigateUrl = CSitemap.External_Amazon("B0089X48M6") 'Complete collection
            End If

            If .ProductSmashwordsId > 0 Then
                lnkSmashwords.NavigateUrl = CSitemap.External_Smashwords(.ProductSmashwordsId)
            ElseIf .HasParent AndAlso .BelongsTo.ProductSmashwordsId > 0 Then
                lnkSmashwords.NavigateUrl = CSitemap.External_Smashwords(.BelongsTo.ProductSmashwordsId)
                'lnkReview.NavigateUrl = CSitemap.External_Review(.BelongsTo.ProductSmashwordsId)
            Else
                lnkSmashwords.Visible = False
                'lnkReview.Visible = False
            End If

            If .HasBook Then
                lnkBook.NavigateUrl = CSitemap.External_CreateSpace(.ProductCSBookIdOrParent)
                If Not IsNothing(.CSPaperback) AndAlso Not String.IsNullOrEmpty(.CSPaperback.ProductAmazonId) Then
                    lnkViaAmazon.Visible = True
                    lnkViaAmazon.NavigateUrl = CSitemap.External_Amazon(.CSPaperback.ProductAmazonId)
                End If
            Else
                lnkBook.Visible = False
            End If

            litSlashVimYou.Visible = lnkVimeo.Visible AndAlso lnkYouTube.Visible
            litSlashViaAmazon.Visible = lnkBook.Visible AndAlso lnkViaAmazon.Visible
            litSlashHtmlEpub.Visible = lnkHtml.Visible AndAlso lnkEPub.Visible
            litSlashEpubMobi.Visible = lnkEPub.Visible AndAlso lnkMobi.Visible
            litKindleSmash.Visible = lnkAmazon.Visible AndAlso lnkSmashwords.Visible
        End With
    End Sub

End Class
